<template>
  <view class="page">
    <tabbar current="1"></tabbar>
    <view class="search-box">
      <view class="tab-search">
        <view class="search-address" @click="FormBoxHandler">
          <image src="../../static/position.png" mode=""></image>
          <view class="area"> {{ searchCity }}</view>
        </view>
        <view class="search-input" @click="toSearch">
          <uni-icons
            slot="searchIcon"
            color="#999999"
            size="18"
            type="search"
          />
          <text>搜索演出</text>
        </view>
      </view>
      <view class="search-sort">
        <scroll-view class="scroll-view" scroll-x="true">
          <view class="scroll-view-item" @click="changeType(-1)">
            <text :class="type === -1 ? 'current-item' : ''">全部</text>
          </view>
          <view
            class="scroll-view-item"
            @click="changeType(item.performanceType)"
            v-for="(item, index) in PerformanceTypes()"
            :key="index"
          >
            <text :class="type === index ? 'current-item' : ''">{{
              item.chineseName
            }}</text>
          </view>
        </scroll-view>
        <uni-icons type="bars" size="30" style="margin-top: 10px"></uni-icons>
      </view>
    </view>
    <view class="sort-order">
      <!-- filterData:筛选数据  defaultIndex： 默认选择序列 @ed:选择事件 返回选择的值-->
      <chenchuang-CCDropDownFilter
        :filterData="filterData"
        :defaultIndex="defaultIndex"
        @ed="ed"
      ></chenchuang-CCDropDownFilter>
    </view>

    <scroll-view
      scroll-y="true"
      lower-threshold="100px"
      @scrolltolower="getList"
      class="concertList-box"
    >
      <concertList
        :concertList="concertList"
        :hasMore="hasMore"
        :loading="loading"
      ></concertList>
    </scroll-view>
  </view>
</template>

<script>
import concertList from "../../uni_modules/uni-badge/components/concert-list/concert-list.vue";
import { getConcertList } from "../../api/user/concert";
import { PerformanceTypes } from "../../utils/PerformanceTypeUtil";
import store from "../../store";

export default {
  components: { concertList },
  data() {
    return {
      concertList: [],
      hasMore: true,
      loading: false,
      type: -1,
      condition: {
        pageNum: 1,
        pageSize: 5,
      },
      filterData: [
        [
          {
            name: "折扣优先",
            value: "",
          },
          {
            name: "时间最近",
            value: "",
          },
          {
            name: "价格低->高",
            value: "",
          },
          {
            name: "价格高->低",
            value: "",
          },
        ],
      ],
      defaultIndex: [0],
    };
  },
  onShow() {
    // 一次性消耗
    this.type =
      this.$store.state.takeType === undefined
        ? -1
        : this.$store.state.takeType;
    store.commit("changeTakeType", undefined);
    // 重新获取页面数据
    this.init();
    this.getList();
  },
  methods: {
    sortChange() {},
    PerformanceTypes() {
      return PerformanceTypes;
    },
    getList() {
      if (!this.hasMore || this.loading) return;
      this.loading = true;
      // 携带上城市
      this.condition.venueCity = this.$store.state.searchCity;
      if (this.type !== -1) this.condition.performanceType = this.type;
      getConcertList(this.condition).then((res) => {
        this.concertList = [...this.concertList, ...res.data.rows];
        this.hasMore =
          this.condition.pageNum * this.condition.pageSize <= res.data.total;
        ++this.condition.pageNum;
        this.loading = false;
      });
    },
    toSearch() {
      uni.navigateTo({
        url: "/subpkg/search/search",
        fail(error) {
          console.log(error);
        },
      });
    },
    FormBoxHandler() {
      this.$emit("ToFormClick");
      uni.navigateTo({
        url: "/subpkg/search-form/search-form",
        fail(error) {
          console.log(error);
        },
      });
    },
    changeType(type) {
      if (this.type === type) return;
      this.type = type;
      this.init();
      this.getList();
    },
    init() {
      // 重新获取页面数据
      this.hasMore = true;
      this.loading = false;
      this.concertList = [];
      this.condition = {
        pageNum: 1,
        pageSize: 5,
      };
    },
  },

  computed: {
    searchCity() {
      return this.$store.state.searchCity;
    },
  },
};
</script>

<style lang="scss">
.page {
  height: calc(100% - 150upx);
}
.sort-order {
  height: 80rpx;
  background-color: white;
}
.search-box {
  z-index: 99;
  width: 100%;
  height: 115px;
  background-color: white;
  box-sizing: border-box;
  padding: 5px 10px;

  .tab-search {
    display: flex;
    width: 100%;
    margin-top: 8px;

    .search-address {
      display: flex;
      width: 25%;
      height: 36px;

      image {
        width: 40%;
        height: 100%;
      }

      .area {
        text-align: center;
        line-height: 36px;
        font-size: 20px;
      }
    }

    .search-input {
      width: 75%;
      height: 36px;
      text-align: center;
      line-height: 36px;
      color: #949494;
      border-radius: 20px;
      background-color: #e7e7e7;
    }
  }

  .search-sort {
    display: flex;
    margin-top: 10px;
    padding-right: 5px;
    width: 100%;
    height: 50px;

    .scroll-view {
      white-space: nowrap;
      width: 94%;
    }

    .scroll-view-item {
      display: inline-block;
      line-height: 50px;
      padding: 0 10px;

      text {
        font-size: 18px;
        color: #888888;
      }

      .current-item {
        font-size: 26px;
        font-weight: 600;
        color: black;
        padding-bottom: 3px;
        border-bottom: 2px solid #000000;
      }
    }
  }
}

.concertList-box {
  height: 80%;
}
</style>
